
#include "wxslcdclock.h"
#include "wx/KWIC/LCDClock.h"

namespace
{
   
    #include "images/lcd16.xpm"
    #include "images/lcd32.xpm"

   
   
    wxsRegisterItem<wxsLCDClock> Reg(
        _T("kwxLCDClock"),                                            
        wxsTWidget,                                                           
        _T("KWIC License"),                                          
        _T("Andrea V. & Marco Cavallini"),                  
        _T("m.cavallini@koansoftware.com"),             
        _T("http://www.koansoftware.com/kwic/"),       
        _T("KWIC"),                                                            
        60,                                                                           
        _T("LCDClock"),                                                  
        wxsCPP,                                                               
        1, 0,                                                                         
        wxBitmap(lcd32_xpm),                                      
        wxBitmap(lcd16_xpm),                                      
        true);                                                                       
}


wxsLCDClock::wxsLCDClock(wxsItemResData* Data) :
    wxsWidget(
        Data,
        &Reg.Info,
        NULL,
        NULL,
        flVariable|flId|flPosition|flSize|flEnabled|flFocused|flHidden|flColours|flToolTip|flHelpText|flSubclass|flMinMaxSize),
        m_iNumDigits(6) {
}


wxsLCDClock::~wxsLCDClock() {
}


void wxsLCDClock::OnBuildCreatingCode() {
    switch ( GetLanguage() )
    {
        case wxsCPP:
        {
            AddHeader(_T("\"wx/KWIC/LCDClock.h\""),GetInfo().ClassName);
            Codef(_T("%C(%W,%P,%S);\n"));

           
            if (m_iNumDigits && m_iNumDigits != 6){
                Codef(_T("%ASetNumberDigits(%d);\n"), static_cast<int>(m_iNumDigits));
            }
            wxString ss = m_cdLightColour.BuildCode( GetCoderContext() );
            if (!ss.IsEmpty()) Codef(_T("%ASetLightColour(%s);\n"), ss.wx_str());

            ss = m_cdGrayColour.BuildCode( GetCoderContext() );
            if (!ss.IsEmpty()) Codef(_T("%ASetGrayColour(%s);\n"), ss.wx_str());

            BuildSetupWindowCode();
            break;
        }
        case wxsUnknownLanguage:
        default:
            wxsCodeMarks::Unknown(_T("wxsLCDClock::OnBuildCreatingCode"),GetLanguage());
    }
}


wxObject* wxsLCDClock::OnBuildPreview(wxWindow* parent, long flags) {
   kwxLCDClock* preview = new kwxLCDClock(parent,Pos(parent),Size(parent));

   
    if(m_iNumDigits && m_iNumDigits != 6){
        preview->SetNumberDigits(m_iNumDigits);
    }
    wxColour cc = m_cdLightColour.GetColour();
    if(cc.IsOk()){
        preview->SetLightColour(cc);
    }
    cc = m_cdGrayColour.GetColour();
    if(cc.IsOk()){
        preview->SetGrayColour(cc);
    }

    return SetupWindow(preview,flags);
}


void wxsLCDClock::OnEnumWidgetProperties(cb_unused long Flags) {
    WXS_LONG(wxsLCDClock, m_iNumDigits, _("Number of digits"), _T("num_digits"), 0)
    WXS_COLOUR(wxsLCDClock, m_cdLightColour , _("Active segments"), _T("active_colour"))
    WXS_COLOUR(wxsLCDClock, m_cdGrayColour, _("Inactive segments"), _T("inactive_colour"))
}

